<template>
    <div>
        <h2>Element Plus Menu with default-active</h2>
        <el-menu
            :default-active="activeIndex"
            class="el-menu-demo"
            mode="vertical"
            @select="handleSelect"
        >
            <el-menu-item index="1">处理中心</el-menu-item>
            <el-menu-item index="2">我的工作台</el-menu-item>
            <el-sub-menu index="3">
                <template #title>消息中心</template>
                <el-menu-item index="3-1">选项1</el-menu-item>
                <el-menu-item index="3-2">选项2</el-menu-item>
            </el-sub-menu>
            <el-menu-item index="4" disabled>订单管理</el-menu-item>
        </el-menu>
        <p v-if="selectedItem">您选择了: {{ selectedItem }}</p>
    </div>
</template>

<script setup>
import { ref } from 'vue'

// 定义响应式数据
const activeIndex = ref('2') // 设置默认激活的菜单项索引
const selectedItem = ref(null) // 保存用户选择的菜单项

// 定义方法
function handleSelect(key) {
    selectedItem.value = key
    console.log(`Selected item: ${key}`)
}
</script>

<style scoped>
.el-menu-demo {
    margin-bottom: 20px;
}
</style>
